const request = require('request');
const config  = require('../config/config');

class elves_plugin{

    constructor() {
    }

    async validCookie(cookie){
        return new Promise((resolve, reject) => {
            let options = {
                url:'https://www.sellersprite.com/v2/extension/keyword/searches/US?q=apple+cutter&tk=909410.978944&version=2.8.2&language=zh_CN&extension=bfpnijhphaeccchggjmheoafglgldceb',
                method:'GET',
                gizp:true,
                headers:{
                    "auth-token":cookie,
                    "accept":"application/json"
                }
            };
            request(options,async (err,response,body) => {
                if (err) {
                    console.log(`Elves plugin request failed... Body:${JSON.stringify(body)}`);
                    resolve(true);
                    return;
                }
                body = JSON.parse(body);
                if(body.code !== 'OK') {
                    console.log(`Elves plugin invalid... Body:${JSON.stringify(body)}`);
                    resolve(false);
                }else if(body.code === 'OK'){
                    console.log(`Elves plugin valid.`);
                    resolve(true);
                }
            })
        })
    }
}
module.exports = elves_plugin;
